<?php
function calcomania_mod($id_veh, $idcolor){
    include (dirname(dirname(__FILE__)).'/Guardado/crearpdf2.php');
  $host	= "localhost";
	$db	= "autoguayanaBD";
	$user	= "postgres";
	$password = "12345";
        $port = "5432";

	// Abrir la Conexión
        $datos = "host=$host port=$port dbname=$db user=$user password=$password";
        $conex= pg_connect($datos)  or die("Error en conexion".pg_last_error());
        
    $sentencia = "select veh.idveh, veh.modelo, veh.np, veh.nc, veh.marca, veh.cap, veh.garantia, veh.preciov, veh.ffab, veh.lfab,veh.seguro,veh.peso, c.descp
                  from  vehiculo as veh, color as c
                  where veh.idveh = $id_veh and c.idcolor=$idcolor;";

    $query2 = pg_query($conex,$sentencia) or die('Consulta fallida: ' . pg_last_error());
        // Redireccion
        
   
     $cuerpo.= "<img src='../img/logo.png' /> <tr>
                        <td colspan='9' align='center'>Calcomania:".$id_veh."</td></tr><table border=1 >
      
                        <thead>  
                        <tr>
                                <th>ID Vehículo</th>
                                <th>Modelo</th>
                                <th>Nro. Puertas</th>
                                <th>Nro. Cilindros</th>  
                                <th>Marca</th>
                                <th>Capacidad</th>
                                <th>Garantía</th>
                                <th>Precio Venta</th>
                                <th>Fecha Fab.</th>
                                <th>Lugar Fab.</th>
                                <th>Seguro</th>
                                <th>Peso</th>
                                <th>ID Color</th>
                        </tr>
                      </thead>"
            ?>
                                
<?php     
         while ($tupla = pg_fetch_array($query2)) {
                    //Guardando tuplas en el pdf
             
                    $cuerpo.= "
                        <tr>
                        <td>  ".$tupla[0]."</td>
                        <td> ".$tupla[1]."</td>
                        <td>  ".$tupla[2]."</td>
                        <td>  ".$tupla[3]."</td>
                        <td>  ".$tupla[4]."</td>   
                        <td>  ".$tupla[5]."</td> 
                        <td> ".$tupla[6]."</td>
                        <td>  ".$tupla[7]."</td>
                        <td>  ".$tupla[8]."</td>
                        <td>  ".$tupla[9]."</td>
                        <td>  ".$tupla[10]."</td>   
                        <td>  ".$tupla[11]."</td>
                        <td> ".$tupla[12]."</td>
                        <td>  ".$tupla[13]."</td>     
                        </tr>";
         }  
                 $cuerpo.= "</table>";
          pg_close($conex);

         crear_pdf($cuerpo,'Calcomania'.$id_veh);
}
function crear_calcomania(){
//  require_once (dirname(dirname(__FILE__))."/plantilla/accesobd.php"); 
  include (dirname(dirname(__FILE__)).'/Guardado/crearpdf2.php');
  $host	= "localhost";
	$db	= "autoguayanaBD";
	$user	= "postgres";
	$password = "12345";
        $port = "5432";

	// Abrir la Conexión
        $datos = "host=$host port=$port dbname=$db user=$user password=$password";
        $conex= pg_connect($datos)  or die("Error en conexion".pg_last_error());
        
  $query = pg_query("select max(idveh) from vehiculo;");
  $id_veh = pg_fetch_array($query);
  $color= "select c.idcolor from color as c;";
   $querycolor = pg_query($conex,$color);
   $idcolor = pg_fetch_array($querycolor); 
    $sentencia = "select veh.idveh, veh.modelo, veh.np, veh.nc, veh.marca, veh.cap, veh.garantia, veh.preciov, veh.ffab, veh.lfab,veh.seguro,veh.peso, c.descp
                  from  vehiculo as veh, color as c
                  where veh.idveh = $id_veh[0] and c.idcolor=$idcolor[0];";

    $query2 = pg_query($conex,$sentencia) or die('Consulta fallida: ' . pg_last_error());
        // Redireccion
        
   
     $cuerpo.= "<img src='../img/logo.png' /> <tr>
                        <td colspan='9' align='center'>Calcomania:".$id_veh[0]."</td></tr><table border=1 >
      
                        <thead>  
                        <tr>
                                <th>ID Vehículo</th>
                                <th>Modelo</th>
                                <th>Nro. Puertas</th>
                                <th>Nro. Cilindros</th>  
                                <th>Marca</th>
                                <th>Capacidad</th>
                                <th>Garantía</th>
                                <th>Precio Venta</th>
                                <th>Fecha Fab.</th>
                                <th>Lugar Fab.</th>
                                <th>Seguro</th>
                                <th>Peso</th>
                                <th>ID Color</th>
                        </tr>
                      </thead>"
            ?>
                                
<?php     
         while ($tupla = pg_fetch_array($query2)) {
                    //Guardando tuplas en el pdf
             
                    $cuerpo.= "
                        <tr>
                        <td>  ".$tupla[0]."</td>
                        <td> ".$tupla[1]."</td>
                        <td>  ".$tupla[2]."</td>
                        <td>  ".$tupla[3]."</td>
                        <td>  ".$tupla[4]."</td>   
                        <td>  ".$tupla[5]."</td> 
                        <td> ".$tupla[6]."</td>
                        <td>  ".$tupla[7]."</td>
                        <td>  ".$tupla[8]."</td>
                        <td>  ".$tupla[9]."</td>
                        <td>  ".$tupla[10]."</td>   
                        <td>  ".$tupla[11]."</td>
                        <td> ".$tupla[12]."</td>
                        <td>  ".$tupla[13]."</td>     
                        </tr>";
         }  
                 $cuerpo.= "</table>";
          pg_close($conex);

         crear_pdf($cuerpo,'Calcomania'.$id_veh[0]);
}
              
?>